function getNetworkImage(url) {
	return new Promise((resolve, reject) => {
		uni.downloadFile({
			url,
			success: (e) => {
				const p = e.tempFilePath
				if (p.indexOf('json') > -1) {
					reject(p)
					return false
				}
				resolve(p)
			},
			fail: (r) => {
				resolve(url)
			}
		})
	})
}
export function posterCanvas(obj, _this) {
	return new Promise(async(resolve, reject)=> {
		let {
			canvasId,
			arr = [],
			bgColor = '#fff',
			cw = 370,
			ch = 500
		} = obj;
		let ctx = uni.createCanvasContext(canvasId, _this);
		ctx.setFillStyle(bgColor);
		ctx.fillRect(0, 0, cw, ch);

		for (let item of arr) {
			if (item.type == 1) {
				let {
					textCtx
				} = item;
				for (let i = 0; i < textCtx.length; i++) {
					ctx.setFillStyle(textCtx[i].color); //文字颜色：默认黑色
					ctx.setFontSize(textCtx[i].fontSize || '10'); //设置字体大小，默认10
					ctx.textAlign = textCtx[i].textAlign || 'left'; // 设置位置
					ctx.fillText(textCtx[i].text, textCtx[i].x, textCtx[i].y);
				}
			} else if (item.type == 2) {
				for (let i = 0; i < item.imgCtx.length; i++) {
					const src = item.imgCtx[i].src;
					let res = await getNetworkImage(src);
					let isArc = item.imgCtx[i].isArc || false;
					if (isArc) {
						ctx.save();
						ctx.beginPath();
						ctx.arc(item.imgCtx[i].w / 2 + item.imgCtx[i].x, item.imgCtx[i].h / 2 + item.imgCtx[i].y, item.imgCtx[i].w / 2,
							0, Math.PI * 2, false);
						ctx.clip();
						ctx.drawImage(res, item.imgCtx[i].x, item.imgCtx[i].y, item.imgCtx[i].w, item.imgCtx[i].h);
						ctx.restore();
					} else {
						ctx.drawImage(res, item.imgCtx[i].x, item.imgCtx[i].y, item.imgCtx[i].w, item.imgCtx[i].h);
					}

				}
			} else if (item.type == 3) {
				let {
					shapeCtx
				} = item;
				for (let i = 0; i < shapeCtx.length; i++) {
					const item = shapeCtx[i]
					ctx.setStrokeStyle(item.color)
					ctx.beginPath()
					ctx.setLineWidth(item.lwid)
					ctx.moveTo(item.x, item.y)
					ctx.lineTo(item.lx, item.ly)
					ctx.setLineDash([0, 0])
					ctx.stroke()
					if(item.solid) {
						ctx.setStrokeStyle(item.color)
						ctx.beginPath()
						ctx.setLineWidth(item.solid.lwid)
						ctx.moveTo(item.solid.x, item.solid.y)
						ctx.lineTo(item.solid.lStart[0], item.solid.lStart[1])
						if(item.solid.lEnd) {
							ctx.lineTo(item.solid.lEnd[0], item.solid.lEnd[1])
						}
						ctx.setLineDash(item.solid.lDash)
						ctx.stroke()
					}
				}
			}
		}
		ctx.draw(false, ()=> {
			uni.canvasToTempFilePath({
				canvasId,
				width: cw,
				height: ch,
				destWidth: cw,
				destHeight: ch,
				success(res) {
					resolve(res)
				}
			}, _this)
		})
	})
}
